<?php


//错误日志
require '../vendor/autoload.php';
use Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()->build();


//_索引一个文档
$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
    'body' => ['testField' => 'abc']
];

$response = $client->index($params);
print_r($response);

//die();

//_获取一个文档
$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id'
];

$response = $client->get($params);
echo  "_获取一个文档"."<BR/>\r\n";
print_r($response);


//_搜索一个文档
$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'body' => [
        'query' => [
            'match' => [
                'testField' => 'abc'
            ]
        ]
    ]
];

$response = $client->search($params);
echo  "_搜索一个文档"."<BR/>\r\n";
print_r($response);


//_删除一个文档
$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id'
];

$response = $client->delete($params);
echo  "_删除一个文档"."<BR/>\r\n";
print_r($response);


//_删除一个索引
$deleteParams = [
    'index' => 'my_index'
];
$response = $client->indices()->delete($deleteParams);
echo  "_删除一个索引"."<BR/>\r\n";
print_r($response);



//_创建一个索引

$params = [
    'index' => 'my_index',
    'body' => [
        'settings' => [
            'number_of_shards' => 2,
            'number_of_replicas' => 0
        ]
    ]
];

$response = $client->indices()->create($params);
echo  "_创建一个索引"."<BR/>\r\n";
print_r($response);


